home *** CD-ROM | disk | FTP | other *** search
/ Delphi Developer's Kit 1996 / Delphi Developer's Kit 1996.iso / power / blade10 / blabel.pas < prev    next >
Pascal/Delphi Source File  |  1995-12-22  |  4KB  |  139 lines

  1. { TBlinkLabel Component v1.00 for Delphi - Freeware by Peak Computing
  2.  
  3.   I wrote this label because I needed some blinking text on a form, it is a *VERY* simplistic
  4.   hack of TLabel, have fun with it!
  5.  
  6.   The only new property added is "BlinkRate" this is the blinking speed of the text in milliseconds,
  7.   the lowest number is 100, highest is 65535.  Note:  If you set this value to zero (0) you will stop
  8.   the text from blinking, it checks to see if you stopped it, and if the text is currently "off" it
  9.   will make sure it is visible again before stopping.
  10.  
  11.   Email help@peak.usa1.com if you have a question/bug/suggestion
  12. }
  13. unit Blabel;
  14.  
  15. interface
  16.  
  17. uses
  18.     Classes, Controls, Forms, StdCtrls, ExtCtrls, Graphics;
  19.  
  20. type
  21.     TBlinkLabel = class(TLabel)
  22.     private
  23.            { Private declarations }
  24.            FBlinkRate:Word;
  25.            Timer1:TTimer;
  26.            Ready, Toggle:Boolean;
  27.            OldColor:TColor;
  28.  
  29.            procedure DoBlink(Sender:TObject);
  30.            procedure SetBlinkRate(value:word);
  31.     protected
  32.            { Protected declarations }
  33.            constructor Create(AOwner : TComponent); override;
  34.            procedure Loaded; override;
  35.     public
  36.            { Public declarations }
  37.     published
  38.            { Published declarations }
  39.            property BlinkRate:word read FBlinkRate write SetBlinkRate default 300;
  40.     end;
  41.  
  42. procedure Register;
  43.  
  44. implementation
  45.  
  46.  
  47. { Set the label's blinking rate }
  48. procedure TBlinkLabel.SetBlinkRate(value:word);
  49. begin
  50.      { Is it 0? }
  51.      if (value=0) then
  52.      begin
  53.           { It is, user wants the blinking to stop, check
  54.             and see if the text is currently invisible }
  55.           if (toggle) then
  56.           begin
  57.                { It was invisible, turn it back on }
  58.                if (font.color=color) then
  59.                   font.color:=oldcolor;
  60.  
  61.                   toggle:=not toggle;
  62.           end;
  63.      end  { Don't allow a value lower than 100, lower doesn't work to well on some machines }
  64.      else if (value<100) then
  65.           value:=100;
  66.  
  67.      FBlinkRate:=value;
  68.  
  69.      { Check to see if the timer is created before trying to assign a value }
  70.      if (Ready) then timer1.interval:=FBlinkRate;
  71. end;
  72.  
  73.  
  74. { Handle timer event }
  75. procedure TBlinkLabel.DoBlink(Sender:TObject);
  76. begin
  77.      { Do blinking }
  78.      if (toggle) then
  79.      begin
  80.           { This "if" statement is to test and see if the user is trying to
  81.             change the label's color, if so, don't put back the old color over
  82.             the one he just set! }
  83.           if (font.color=color) then
  84.              font.color:=oldcolor;
  85.  
  86.           toggle:=not toggle;
  87.      end
  88.      else
  89.      begin
  90.           oldcolor:=font.color;
  91.           font.color:=color;
  92.           toggle:=not toggle;
  93.      end;
  94. end;
  95.  
  96.  
  97. { Create our component }
  98. constructor TBlinkLabel.Create(AOwner : TComponent);
  99. begin
  100.      inherited Create(AOwner);
  101.  
  102.      { Set default blink-rate }
  103.      BlinkRate:=300;
  104.  
  105.      invalidate;
  106. end;
  107.  
  108.  
  109. { This is run when the component is loaded }
  110. procedure TBlinkLabel.Loaded;
  111. begin
  112.      inherited loaded;
  113.  
  114.      { Is it still in design-time?  If so, exit.
  115.        (I found having it blink while designing was
  116.         annoying and messed up sometimes, so it only
  117.         blinks when the application is running)}
  118.      if (csDesigning in ComponentState) then exit;
  119.  
  120.      { Create timer and setup event }
  121.      timer1:=TTimer.create(self);
  122.      timer1.interval:=FBlinkRate;
  123.      timer1.ontimer:=DoBlink;
  124.      timer1.enabled:=true;
  125.  
  126.      { Init some varibles }
  127.      toggle:=false;
  128.      ready:=true;
  129. end;
  130.  
  131.  
  132. { Register our component }
  133. procedure Register;
  134. begin
  135.      RegisterComponents('Standard', [TBlinkLabel]);
  136. end;
  137.  
  138. end.
  139.